﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace Web.group
{
    public partial class BranchOfficeEdit : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (string.IsNullOrWhiteSpace(Request["id"]))
                {
                    throw new Base.CustomException("缺少参数id");
                }

                Hashtable editbo = PhoneBook.Group.BranchOffice.get(Request["id"]);

                if (editbo == null)
                {
                    throw new Base.CustomException("参数id不正确");
                }

                txbboname.Text = editbo["boname"].ToString();
            }
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txbboname.Text.Trim()))
            {
                Helper.ShowMessage(u_message, controls.UCMessageType.attention, "请输入分公司名称");
                return;
            }
            Hashtable newbo = PhoneBook.Users.Users.get(Commons.StrUtil.FormatValue(Request["id"]));
            addLog(newbo);
            newbo["boname"] = txbboname.Text.Trim();

            PhoneBook.Group.BranchOffice.edit(newbo);

            Helper.ShowMessage(u_message, controls.UCMessageType.success, "保存成功");
        }

        //添加日志
        private void addLog(Hashtable bo)
        {
            string content = string.Empty;

            if (bo["boname"].ToString() != txbboname.Text.Trim())
                content += string.Format("分公司名:{0}->{1};", bo["boname"], txbboname.Text);

            if (!string.IsNullOrEmpty(content))
            {
                content = string.Format("修改了分公司信息({0})。{1}", bo["boname"], content);

                AddLog(content);
            }
        }
    }
}